package com.jalarbee.stock.product.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;

import com.jalarbee.core.generic.dao.GenericDao;
import com.jalarbee.core.generic.service.impl.GenericServiceImpl;
import com.jalarbee.core.util.Chunk;
import com.jalarbee.stock.category.exception.NoSuchCategoryException;
import com.jalarbee.stock.product.business.Product;
import com.jalarbee.stock.product.dao.ProductDao;
import com.jalarbee.stock.product.service.ProductService;
import javax.inject.Inject;
import javax.inject.Named;

@Named(value = "productService")
@Transactional(readOnly = true)
public class ProductServiceImpl extends GenericServiceImpl<Product, Integer> implements ProductService {

    @Override
    @Inject
    protected void setDao(@Qualifier(value = "productDao") GenericDao<Product, Integer> dao) {
        this.dao = dao;
    }

    @Override
    public List<Product> getProductsByCategory(int categoryId, Chunk chunk) throws NoSuchCategoryException {
        try {
            return ((ProductDao) dao).getProductsByCategory(categoryId, chunk);
        } catch (NoSuchCategoryException e) {
            logger.error(e);
            throw e;
        }
    }

    @Override
    public void inactivate(Product product) {
        ((ProductDao) dao).inactivate(product);
    }

    @Override
    public void activate(Product product) {
        ((ProductDao) dao).inactivate(product);
    }
}
